<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta content="Cask Data, Inc." name="author" />
<meta content="Copyright © 2014-2017 Cask Data, Inc." name="copyright" />


    <meta name="git_release" content="6.1.1">
    <meta name="git_hash" content="05fbac36f9f7aadeb44f5728cea35136dbc243e5">
    <meta name="git_timestamp" content="2020-02-09 08:22:47 +0800">
    <title>Java Client API</title>

    <link rel="stylesheet" href="_static/cdap-bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/bootstrap-3.3.6/css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="_static/bootstrap-3.3.6/css/bootstrap-theme.min.css" type="text/css" />
    <link rel="stylesheet" href="_static/css/bootstrap-sphinx.css" type="text/css" />
    <link rel="stylesheet" href="_static/css/cdap-dynamicscrollspy-4.css" type="text/css" />
    <link rel="stylesheet" href="_static/css/jquery.mCustomScrollbar.css" type="text/css" />
    <link rel="stylesheet" href="_static/css/cdap-jquery.mCustomScrollbar.css" type="text/css" />
    <link rel="stylesheet" href="_static/css/abixTreeList-2.css" type="text/css" />
    <link rel="stylesheet" href="_static/cdap-bootstrap.css" type="text/css" />

    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '6.1.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/language_data.js"></script>

    <link rel="shortcut icon" href="_static/favicon.ico"/>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="Cask Data Application Platform 6.1.1 Documentation" href="index.html" />
    <link rel="next" title="Javadocs" href="javadocs/index.html" />
    <link rel="prev" title="Workflow HTTP RESTful API" href="http-restful-api/workflow.html" />
    <!-- block extrahead -->
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <!-- block extrahead end -->

</head>
<body role="document">

<!-- block navbar -->
<div id="navbar" class="navbar navbar-inverse navbar-default navbar-fixed-top">
    <div class="container-fluid">
      <div class="row">
        <div class="navbar-header">
          <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
          <a class="navbar-brand" href="table-of-contents/../../index.html">
            <span><img alt="CDAP logo" src="_static/cdap_logo.svg"/></span>
          </a>

          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>

          <div class="pull-right">
            <div class="dropdown version-dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                role="button" aria-haspopup="true" aria-expanded="false">
                v 6.1.1 <span class="caret"></span>
              </a>
              <ul class="dropdown-menu">
                <li><a href="//docs.cdap.io/cdap/5.1.2/en/index.html">v 5.1.2</a></li>
                <li><a href="//docs.cdap.io/cdap/4.3.4/en/index.html">v 4.3.4</a></li>
              </ul>
            </div>
          </div>
          <form class="navbar-form navbar-right navbar-search" action="search.html" method="get">
            <div class="form-group">
              <div class="navbar-search-image material-icons"></div>
              <input type="text" name="q" class="form-control" placeholder="  Search" />
            </div>
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>

          <div class="collapse navbar-collapse nav-collapse navbar-right navbar-navigation">
            <ul class="nav navbar-nav"><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link " href="table-of-contents/../../index.html">简介</a></li><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link " href="table-of-contents/../../guides.html">手册</a></li><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link current" href="table-of-contents/../../reference-manual/index.html">参考</a></li><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link " href="table-of-contents/../../faqs/index.html">帮助</a></li>
            </ul>
          </div>

        </div>
      </div>
    </div>
  </div><!-- block navbar end -->
<!-- block main content -->
<div class="main-container container">
  <div class="row"><div class="col-md-2">
      <div id="sidebar" class="bs-sidenav scrollable-y-outside" role="complementary">
<!-- theme_manual: reference-manual -->
<!-- theme_manual_highlight: reference -->
<!-- sidebar_title_link: Reference -->

  <div role="note" aria-label="manuals links"><h3>Reference</h3>
    <ul class="reference-page-menu">
      <nav class="pagenav">
      <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="index.html"> Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="characters.html"> Supported Characters</a></li>
<li class="toctree-l1"><a class="reference internal" href="cli-api.html"> Command Line Interface API</a></li>
<li class="toctree-l1"><a class="reference internal" href="http-restful-api/index.html"> HTTP RESTful API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/introduction.html">Introduction</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/artifact.html">Artifact</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/configuration.html">Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/dataset.html">Dataset</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/lifecycle.html">Lifecycle</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/logging.html">Logging</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/metadata.html">Metadata</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/metrics.html">Metrics</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/monitor.html">Monitor</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/namespace.html">Namespace</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/dashboard.html">Dashboard</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/preferences.html">Preferences</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/profile.html">Profile</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/query.html">Query</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/reports.html">Reports</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/security.html">Security</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/service.html">Service</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/transactions.html">Transactions</a></li>
<li class="toctree-l2"><a class="reference internal" href="http-restful-api/workflow.html">Workflow</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="current reference internal" href="#"> Java Client API</a></li>
<li class="toctree-l1"><a class="reference internal" href="javadocs/index.html"> Javadocs</a></li>
<li class="toctree-l1"><a class="reference internal" href="release-notes.html"> 发行说明</a></li>
<li class="toctree-l1"><a class="reference internal" href="licenses/index.html"> Trademarks, Licenses, and Dependencies</a></li>
<li class="toctree-l1"><a class="reference internal" href="glossary.html"> 术语表</a></li>
<li class="toctree-l1"><a class="reference internal" href="genindex.html"> Index</a></li>
</ul>
</nav>
    </ul>
  </div></div>
    </div><div class="col-md-8 content" id="main-content">
    
  <div class="section" id="java-client-api">
<span id="client-api"></span><span id="id1"></span><h1>Java Client API<a class="headerlink" href="#java-client-api" title="Permalink to this headline">🔗</a></h1>
<p>The Cask Data Application Platform (CDAP) Java Client API provides methods for interacting
with CDAP from Java applications.</p>
<div class="section" id="maven-dependency">
<h2>Maven Dependency<a class="headerlink" href="#maven-dependency" title="Permalink to this headline">🔗</a></h2>
<p>To use the Java Client API in your project, add this Maven dependency:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&lt;dependency&gt;</span>
<span class="go">  &lt;groupId&gt;io.cdap.cdap&lt;/groupId&gt;</span>
<span class="go">  &lt;artifactId&gt;cdap-client&lt;/artifactId&gt;</span>
<span class="go">  &lt;version&gt;${cdap.version}&lt;/version&gt;</span>
<span class="go">&lt;/dependency&gt;</span>
</pre></div>
</div>
</div>
<div class="section" id="components">
<h2>Components<a class="headerlink" href="#components" title="Permalink to this headline">🔗</a></h2>
<p>The Java Client API allows you to interact with these CDAP components:</p>
<ul class="simple">
<li><a class="reference external" href="#application-client">ApplicationClient:</a> interacting with applications</li>
<li><a class="reference external" href="#dataset-client">DatasetClient:</a> interacting with datasets</li>
<li><a class="reference external" href="#dataset-module-client">DatasetModuleClient:</a> interacting with dataset Modules</li>
<li><a class="reference external" href="#dataset-type-client">DatasetTypeClient:</a> interacting with dataset Types</li>
<li><a class="reference external" href="#metrics-client">MetricsClient:</a> interacting with metrics</li>
<li><a class="reference external" href="#monitor-client">MonitorClient:</a> monitoring system services</li>
<li><a class="reference external" href="#preferences-client">PreferencesClient:</a> interacting with preferences</li>
<li><a class="reference external" href="#program-client">ProgramClient:</a> interacting with flows, MapReduce Programs, user services, workflows, and workers</li>
<li><a class="reference external" href="#query-client">QueryClient:</a> querying datasets</li>
<li><a class="reference external" href="#service-client">ServiceClient:</a> interacting with user services</li>
<li><a class="reference external" href="#stream-client">StreamClient:</a> interacting with streams</li>
</ul>
<p>The above list links to the examples below for each portion of the API.</p>
</div>
<div class="section" id="configuring-your-client">
<span id="client-api-configuring-client"></span><h2>Configuring your *Client<a class="headerlink" href="#configuring-your-client" title="Permalink to this headline">🔗</a></h2>
<p>Every <em>*Client</em> constructor requires a <cite>ClientConfig</cite> instance which configures the hostname and port of the CDAP
instance that you wish to interact with.</p>
<p>In a non-secure (default) CDAP instance, instantiate as follows:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Interact with the CDAP instance located at example.com, port 11015</span>
<span class="n">ClientConfig</span> <span class="n">clientConfig</span> <span class="o">=</span> <span class="n">ClientConfig</span><span class="p">.</span><span class="na">builder</span><span class="p">()</span>
  <span class="p">.</span><span class="na">setConnectionConfig</span><span class="p">(</span><span class="k">new</span> <span class="n">ConnectionConfig</span><span class="p">(</span><span class="s">&quot;example.com&quot;</span><span class="p">,</span> <span class="mi">11015</span><span class="p">,</span> <span class="kc">false</span><span class="p">))</span>
  <span class="p">.</span><span class="na">build</span><span class="p">();</span>
</pre></div>
</div>
<p>In a secure CDAP instance, first pull in the <code class="docutils literal notranslate"><span class="pre">cdap-authentication-client</span></code> Maven dependency:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">dependency</span><span class="o">&gt;</span>
  <span class="o">&lt;</span><span class="n">groupId</span><span class="o">&gt;</span><span class="n">io</span><span class="p">.</span><span class="na">cdap</span><span class="p">.</span><span class="na">cdap</span><span class="o">&lt;/</span><span class="n">groupId</span><span class="o">&gt;</span>
  <span class="o">&lt;</span><span class="n">artifactId</span><span class="o">&gt;</span><span class="n">cdap</span><span class="o">-</span><span class="n">authentication</span><span class="o">-</span><span class="n">client</span><span class="o">&lt;/</span><span class="n">artifactId</span><span class="o">&gt;</span>
  <span class="o">&lt;</span><span class="n">version</span><span class="o">&gt;</span><span class="n">$</span><span class="p">{</span><span class="n">cdap</span><span class="p">.</span><span class="na">client</span><span class="p">.</span><span class="na">version</span><span class="p">}</span><span class="o">&lt;/</span><span class="n">version</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">dependency</span><span class="o">&gt;</span>
</pre></div>
</div>
<p>Then, instantiate as follows:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Obtain AccessToken</span>
<span class="n">AuthenticationClient</span> <span class="n">authenticationClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">BasicAuthenticationClient</span><span class="p">();</span>
<span class="n">authenticationClient</span><span class="p">.</span><span class="na">setConnectionInfo</span><span class="p">(</span><span class="s">&quot;example.com&quot;</span><span class="p">,</span> <span class="mi">11015</span><span class="p">,</span> <span class="n">sslEnabled</span><span class="p">);</span>
<span class="c1">// Configure the AuthenticationClient as documented in</span>
<span class="c1">// https://github.com/cdapio/cdap-clients/blob/develop/cdap-authentication-clients/java</span>
<span class="n">AccessToken</span> <span class="n">accessToken</span> <span class="o">=</span> <span class="n">authenticationClient</span><span class="p">.</span><span class="na">getAccessToken</span><span class="p">();</span>

<span class="c1">// Interact with the secure CDAP instance located at example.com, port 11015, with the provided accessToken</span>
<span class="n">ClientConfig</span> <span class="n">clientConfig</span> <span class="o">=</span> <span class="n">ClientConfig</span><span class="p">.</span><span class="na">builder</span><span class="p">()</span>
  <span class="p">.</span><span class="na">setConnectionConfig</span><span class="p">(</span><span class="k">new</span> <span class="n">ConnectionConfig</span><span class="p">(</span><span class="s">&quot;example.com&quot;</span><span class="p">,</span> <span class="mi">11015</span><span class="p">,</span> <span class="n">sslEnabled</span><span class="p">))</span>
  <span class="p">.</span><span class="na">setAccessToken</span><span class="p">(</span><span class="n">accessToken</span><span class="p">)</span>
  <span class="p">.</span><span class="na">build</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="application-client">
<span id="id2"></span><h2>ApplicationClient<a class="headerlink" href="#application-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">ApplicationClient</span> <span class="n">appClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ApplicationClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Fetch the list of applications</span>
<span class="n">List</span><span class="o">&lt;</span><span class="n">ApplicationRecord</span><span class="o">&gt;</span> <span class="n">apps</span> <span class="o">=</span> <span class="n">appClient</span><span class="p">.</span><span class="na">list</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">);</span>

<span class="c1">// Deploy an application</span>
<span class="n">File</span> <span class="n">appJarFile</span> <span class="o">=</span> <span class="k">new</span> <span class="n">File</span><span class="p">(</span><span class="s">&quot;your-app.jar&quot;</span><span class="p">);</span>
<span class="n">appClient</span><span class="p">.</span><span class="na">deploy</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">,</span> <span class="n">appJarFile</span><span class="p">);</span>

<span class="c1">// Delete an application</span>
<span class="n">appClient</span><span class="p">.</span><span class="na">delete</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;Purchase&quot;</span><span class="p">));</span>

<span class="c1">// List programs belonging to an application</span>
<span class="n">appClient</span><span class="p">.</span><span class="na">listPrograms</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;Purchase&quot;</span><span class="p">));</span>
</pre></div>
</div>
</div>
<div class="section" id="dataset-client">
<span id="id3"></span><h2>DatasetClient<a class="headerlink" href="#dataset-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">DatasetClient</span> <span class="n">datasetClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DatasetClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Fetch the list of datasets</span>
<span class="n">List</span><span class="o">&lt;</span><span class="n">DatasetSpecificationSummary</span><span class="o">&gt;</span> <span class="n">datasets</span> <span class="o">=</span> <span class="n">datasetClient</span><span class="p">.</span><span class="na">list</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">);</span>

<span class="c1">// Create a dataset</span>
<span class="n">DatasetId</span> <span class="n">datasetId</span> <span class="o">=</span> <span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">dataset</span><span class="p">(</span><span class="s">&quot;someDataset&quot;</span><span class="p">);</span>
<span class="n">datasetClient</span><span class="p">.</span><span class="na">create</span><span class="p">(</span><span class="n">datasetId</span><span class="p">,</span> <span class="s">&quot;someDatasetType&quot;</span><span class="p">);</span>

<span class="c1">// Truncate a dataset</span>
<span class="n">datasetClient</span><span class="p">.</span><span class="na">truncate</span><span class="p">(</span><span class="n">datasetId</span><span class="p">);</span>

<span class="c1">// Delete a dataset</span>
<span class="n">datasetClient</span><span class="p">.</span><span class="na">delete</span><span class="p">(</span><span class="n">datasetId</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="dataset-module-client">
<span id="id4"></span><h2>DatasetModuleClient<a class="headerlink" href="#dataset-module-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">DatasetModuleClient</span> <span class="n">datasetModuleClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DatasetModuleClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Add a dataset module</span>
<span class="n">File</span> <span class="n">moduleJarFile</span> <span class="o">=</span> <span class="n">createAppJarFile</span><span class="p">(</span><span class="n">SomeDatasetModule</span><span class="p">.</span><span class="na">class</span><span class="p">);</span>
<span class="n">DatasetModuleId</span> <span class="n">datasetModuleId</span> <span class="o">=</span> <span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">datasetModule</span><span class="p">(</span><span class="s">&quot;someDatasetModule&quot;</span><span class="p">);</span>
<span class="n">datasetModuleClient</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="n">datasetModuleId</span><span class="p">,</span> <span class="n">SomeDatasetModule</span><span class="p">.</span><span class="na">class</span><span class="p">.</span><span class="na">getName</span><span class="p">(),</span> <span class="n">moduleJarFile</span><span class="p">);</span>

<span class="c1">// Fetch the dataset module information</span>
<span class="n">DatasetModuleMeta</span> <span class="n">datasetModuleMeta</span> <span class="o">=</span> <span class="n">datasetModuleClient</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">datasetModuleId</span><span class="p">);</span>

<span class="c1">// Delete all dataset modules</span>
<span class="n">datasetModuleClient</span><span class="p">.</span><span class="na">deleteAll</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="dataset-type-client">
<span id="id5"></span><h2>DatasetTypeClient<a class="headerlink" href="#dataset-type-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">DatasetTypeClient</span> <span class="n">datasetTypeClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DatasetTypeClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Fetch the dataset type information using the type name</span>
<span class="n">DatasetTypeMeta</span> <span class="n">datasetTypeMeta</span> <span class="o">=</span> <span class="n">datasetTypeClient</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">datasetType</span><span class="p">(</span><span class="s">&quot;someDatasetType&quot;</span><span class="p">));</span>

<span class="c1">// Fetch the dataset type information using the classname</span>
<span class="n">datasetTypeMeta</span> <span class="o">=</span> <span class="n">datasetTypeClient</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">datasetType</span><span class="p">(</span><span class="n">SomeDataset</span><span class="p">.</span><span class="na">class</span><span class="p">.</span><span class="na">getName</span><span class="p">()));</span>
</pre></div>
</div>
</div>
<div class="section" id="metrics-client">
<span id="id6"></span><h2>MetricsClient<a class="headerlink" href="#metrics-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">MetricsClient</span> <span class="n">metricsClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">MetricsClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Fetch the total number of requests that have been processed by a service</span>
<span class="n">RuntimeMetrics</span> <span class="n">metric</span> <span class="o">=</span> <span class="n">metricsClient</span><span class="p">.</span><span class="na">getServiceMetrics</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;SportResults&quot;</span><span class="p">).</span><span class="na">service</span><span class="p">(</span><span class="s">&quot;RetrieveCounts&quot;</span><span class="p">));</span>
<span class="kt">long</span> <span class="n">processed</span> <span class="o">=</span> <span class="n">metric</span><span class="p">.</span><span class="na">getProcessed</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="monitor-client">
<span id="id7"></span><h2>MonitorClient<a class="headerlink" href="#monitor-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">MonitorClient</span> <span class="n">monitorClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">MonitorClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Fetch the list of system services</span>
<span class="n">List</span><span class="o">&lt;</span><span class="n">SystemServiceMeta</span><span class="o">&gt;</span> <span class="n">services</span> <span class="o">=</span> <span class="n">monitorClient</span><span class="p">.</span><span class="na">listSystemServices</span><span class="p">();</span>

<span class="c1">// Fetch status of system transaction service</span>
<span class="n">String</span> <span class="n">serviceStatus</span> <span class="o">=</span> <span class="n">monitorClient</span><span class="p">.</span><span class="na">getSystemServiceStatus</span><span class="p">(</span><span class="s">&quot;transaction&quot;</span><span class="p">);</span>

<span class="c1">// Fetch the number of instances of the system transaction service</span>
<span class="kt">int</span> <span class="n">systemServiceInstances</span> <span class="o">=</span> <span class="n">monitorClient</span><span class="p">.</span><span class="na">getSystemServiceInstances</span><span class="p">(</span><span class="s">&quot;transaction&quot;</span><span class="p">);</span>

<span class="c1">// Set the number of instances of the system transaction service</span>
<span class="n">monitorClient</span><span class="p">.</span><span class="na">setSystemServiceInstances</span><span class="p">(</span><span class="s">&quot;transaction&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="preferences-client">
<span id="id8"></span><h2>PreferencesClient<a class="headerlink" href="#preferences-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">PreferencesClient</span> <span class="n">preferencesClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">PreferencesClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">String</span><span class="o">&gt;</span> <span class="n">propMap</span> <span class="o">=</span> <span class="n">Maps</span><span class="p">.</span><span class="na">newHashMap</span><span class="p">();</span>
<span class="n">propMap</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">&quot;k1&quot;</span><span class="p">,</span> <span class="s">&quot;v1&quot;</span><span class="p">);</span>

<span class="c1">// Set preferences at the Instance level</span>
<span class="n">preferencesClient</span><span class="p">.</span><span class="na">setInstancePreferences</span><span class="p">(</span><span class="n">propMap</span><span class="p">);</span>

<span class="c1">// Get preferences at the Instance level</span>
<span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">String</span><span class="o">&gt;</span> <span class="n">currentPropMap</span> <span class="o">=</span> <span class="n">preferencesClient</span><span class="p">.</span><span class="na">getInstancePreferences</span><span class="p">();</span>

<span class="c1">// Delete preferences at the Instance level</span>
<span class="n">preferencesClient</span><span class="p">.</span><span class="na">deleteInstancePreferences</span><span class="p">();</span>

<span class="c1">// Set preferences of MyApp application which is deployed in the Dev namespace</span>
<span class="n">preferencesClient</span><span class="p">.</span><span class="na">setApplicationPreferences</span><span class="p">(</span><span class="k">new</span> <span class="n">NamespaceId</span><span class="p">(</span><span class="s">&quot;Dev&quot;</span><span class="p">).</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;MyApp&quot;</span><span class="p">),</span> <span class="n">propMap</span><span class="p">);</span>

<span class="c1">// Get only the preferences of MyApp application which is deployed in the Dev namespace</span>
<span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">String</span><span class="o">&gt;</span> <span class="n">appPrefs</span> <span class="o">=</span> <span class="n">preferencesClient</span><span class="p">.</span><span class="na">getApplicationPreferences</span><span class="p">(</span><span class="k">new</span> <span class="n">NamespaceId</span><span class="p">(</span><span class="s">&quot;Dev&quot;</span><span class="p">).</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;MyApp&quot;</span><span class="p">),</span> <span class="kc">false</span><span class="p">);</span>

<span class="c1">// Get the resolved preferences (collapsed with higher level(s) of preferences)</span>
<span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">String</span><span class="o">&gt;</span> <span class="n">resolvedAppPrefs</span> <span class="o">=</span> <span class="n">preferencesClient</span><span class="p">.</span><span class="na">getApplicationPreferences</span><span class="p">(</span><span class="k">new</span> <span class="n">NamespaceId</span><span class="p">(</span><span class="s">&quot;Dev&quot;</span><span class="p">).</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;MyApp&quot;</span><span class="p">),</span> <span class="kc">true</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="program-client">
<span id="id9"></span><h2>ProgramClient<a class="headerlink" href="#program-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">ProgramClient</span> <span class="n">programClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ProgramClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Start a service in the WordCount example</span>
<span class="n">programClient</span><span class="p">.</span><span class="na">start</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;WordCount&quot;</span><span class="p">).</span><span class="na">service</span><span class="p">(</span><span class="s">&quot;RetrieveCounts&quot;</span><span class="p">));</span>

<span class="c1">// formatted in JSON</span>
<span class="n">programClient</span><span class="p">.</span><span class="na">getLiveInfo</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;SportResults&quot;</span><span class="p">).</span><span class="na">service</span><span class="p">(</span><span class="s">&quot;UploadService&quot;</span><span class="p">));</span>

<span class="c1">// Fetch program logs in the WordCount example</span>
<span class="n">programClient</span><span class="p">.</span><span class="na">getProgramLogs</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;WordCount&quot;</span><span class="p">).</span><span class="na">service</span><span class="p">(</span><span class="s">&quot;RetrieveCounts&quot;</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="n">Long</span><span class="p">.</span><span class="na">MAX_VALUE</span><span class="p">);</span>

<span class="c1">// Scale a service in the SportResults example</span>
<span class="n">programClient</span><span class="p">.</span><span class="na">setServiceInstances</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;SportResults&quot;</span><span class="p">).</span><span class="na">service</span><span class="p">(</span><span class="s">&quot;UploadService&quot;</span><span class="p">),</span> <span class="mi">3</span><span class="p">);</span>

<span class="c1">// Stop a service in the SportResults example</span>
<span class="n">programClient</span><span class="p">.</span><span class="na">stop</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;SportResults&quot;</span><span class="p">).</span><span class="na">service</span><span class="p">(</span><span class="s">&quot;UploadService&quot;</span><span class="p">));</span>

<span class="c1">// Start, scale, and stop a flow in the WordCount example</span>
<span class="n">programClient</span><span class="p">.</span><span class="na">start</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;WordCount&quot;</span><span class="p">).</span><span class="na">flow</span><span class="p">(</span><span class="s">&quot;WordCountFlow&quot;</span><span class="p">));</span>

<span class="c1">// Fetch the last 10 flow runs in the WordCount example</span>
<span class="n">programClient</span><span class="p">.</span><span class="na">getAllProgramRuns</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;WordCount&quot;</span><span class="p">).</span><span class="na">flow</span><span class="p">(</span><span class="s">&quot;WordCountFlow&quot;</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="n">Long</span><span class="p">.</span><span class="na">MAX_VALUE</span><span class="p">,</span> <span class="mi">10</span><span class="p">);</span>

<span class="c1">// Scale a flowlet in the WordCount example</span>
<span class="n">programClient</span><span class="p">.</span><span class="na">setFlowletInstances</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;WordCount&quot;</span><span class="p">).</span><span class="na">flow</span><span class="p">(</span><span class="s">&quot;WordCountFlow&quot;</span><span class="p">).</span><span class="na">flowlet</span><span class="p">(</span><span class="s">&quot;Tokenizer&quot;</span><span class="p">),</span> <span class="mi">3</span><span class="p">);</span>

<span class="c1">// Stop a flow in the WordCount example</span>
<span class="n">programClient</span><span class="p">.</span><span class="na">stop</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;WordCount&quot;</span><span class="p">).</span><span class="na">flow</span><span class="p">(</span><span class="s">&quot;WordCountFlow&quot;</span><span class="p">));</span>
</pre></div>
</div>
</div>
<div class="section" id="query-client">
<span id="id10"></span><h2>QueryClient<a class="headerlink" href="#query-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">QueryClient</span> <span class="n">queryClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">QueryClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Perform an ad-hoc query using the Purchase example</span>
<span class="n">ListenableFuture</span><span class="o">&lt;</span><span class="n">ExploreExecutionResult</span><span class="o">&gt;</span> <span class="n">resultFuture</span> <span class="o">=</span> <span class="n">queryClient</span><span class="p">.</span><span class="na">execute</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">,</span> <span class="s">&quot;SELECT * FROM dataset_history WHERE customer IN (&#39;Alice&#39;,&#39;Bob&#39;)&quot;</span><span class="p">);</span>
<span class="n">ExploreExecutionResult</span> <span class="n">results</span> <span class="o">=</span> <span class="n">resultFuture</span><span class="p">.</span><span class="na">get</span><span class="p">();</span>

<span class="c1">// Fetch schema</span>
<span class="n">List</span><span class="o">&lt;</span><span class="n">ColumnDesc</span><span class="o">&gt;</span> <span class="n">schema</span> <span class="o">=</span> <span class="n">results</span><span class="p">.</span><span class="na">getResultSchema</span><span class="p">();</span>
<span class="n">String</span><span class="o">[]</span> <span class="n">header</span> <span class="o">=</span> <span class="k">new</span> <span class="n">String</span><span class="o">[</span><span class="n">schema</span><span class="p">.</span><span class="na">size</span><span class="p">()</span><span class="o">]</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">header</span><span class="p">.</span><span class="na">length</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
  <span class="n">ColumnDesc</span> <span class="n">column</span> <span class="o">=</span> <span class="n">schema</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
  <span class="c1">// Hive columns start at 1</span>
  <span class="kt">int</span> <span class="n">index</span> <span class="o">=</span> <span class="n">column</span><span class="p">.</span><span class="na">getPosition</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
  <span class="n">header</span><span class="o">[</span><span class="n">index</span><span class="o">]</span> <span class="o">=</span> <span class="n">column</span><span class="p">.</span><span class="na">getName</span><span class="p">()</span> <span class="o">+</span> <span class="s">&quot;: &quot;</span> <span class="o">+</span> <span class="n">column</span><span class="p">.</span><span class="na">getType</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="service-client">
<span id="id11"></span><h2>ServiceClient<a class="headerlink" href="#service-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">ServiceClient</span> <span class="n">serviceClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ServiceClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Fetch service information using the service in the PurchaseApp example</span>
<span class="n">ServiceSpecification</span> <span class="n">serviceSpec</span> <span class="o">=</span> <span class="n">serviceClient</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">app</span><span class="p">(</span><span class="s">&quot;PurchaseApp&quot;</span><span class="p">).</span><span class="na">service</span><span class="p">(</span><span class="s">&quot;CatalogLookup&quot;</span><span class="p">));</span>
</pre></div>
</div>
</div>
<div class="section" id="stream-client">
<span id="id12"></span><h2>StreamClient<a class="headerlink" href="#stream-client" title="Permalink to this headline">🔗</a></h2>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">ClientConfig</span> <span class="n">clientConfig</span><span class="p">;</span>

<span class="c1">// Construct the client used to interact with CDAP</span>
<span class="n">StreamClient</span> <span class="n">streamClient</span> <span class="o">=</span> <span class="k">new</span> <span class="n">StreamClient</span><span class="p">(</span><span class="n">clientConfig</span><span class="p">);</span>

<span class="c1">// Fetch the stream list</span>
<span class="n">List</span> <span class="n">streams</span> <span class="o">=</span> <span class="n">streamClient</span><span class="p">.</span><span class="na">list</span><span class="p">(</span><span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">);</span>

<span class="c1">// Create a stream, using the Purchase example</span>
<span class="n">StreamId</span> <span class="n">streamId</span> <span class="o">=</span> <span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">stream</span><span class="p">(</span><span class="s">&quot;purchases&quot;</span><span class="p">);</span>
<span class="n">streamClient</span><span class="p">.</span><span class="na">create</span><span class="p">(</span><span class="n">streamId</span><span class="p">);</span>

<span class="c1">// Fetch a stream&#39;s properties</span>
<span class="n">StreamProperties</span> <span class="n">config</span> <span class="o">=</span> <span class="n">streamClient</span><span class="p">.</span><span class="na">getConfig</span><span class="p">(</span><span class="n">streamId</span><span class="p">);</span>

<span class="c1">// Send events to a stream</span>
<span class="n">streamClient</span><span class="p">.</span><span class="na">sendEvent</span><span class="p">(</span><span class="n">streamId</span><span class="p">,</span> <span class="s">&quot;Tom bought 5 apples for $10&quot;</span><span class="p">);</span>

<span class="c1">// Read all events from a stream (results in events)</span>
<span class="n">List</span><span class="o">&lt;</span><span class="n">StreamEvent</span><span class="o">&gt;</span> <span class="n">events</span> <span class="o">=</span> <span class="n">Lists</span><span class="p">.</span><span class="na">newArrayList</span><span class="p">();</span>
<span class="n">streamClient</span><span class="p">.</span><span class="na">getEvents</span><span class="p">(</span><span class="n">streamId</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">Long</span><span class="p">.</span><span class="na">MAX_VALUE</span><span class="p">,</span> <span class="n">Integer</span><span class="p">.</span><span class="na">MAX_VALUE</span><span class="p">,</span> <span class="n">events</span><span class="p">);</span>

<span class="c1">// Read first 5 events from a stream (results in events)</span>
<span class="n">events</span> <span class="o">=</span> <span class="n">Lists</span><span class="p">.</span><span class="na">newArrayList</span><span class="p">();</span>
<span class="n">streamClient</span><span class="p">.</span><span class="na">getEvents</span><span class="p">(</span><span class="n">streamId</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">Long</span><span class="p">.</span><span class="na">MAX_VALUE</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="n">events</span><span class="p">);</span>

<span class="c1">// Read 2nd and 3rd events from a stream, after first calling getEvents</span>
<span class="kt">long</span> <span class="n">startTime</span> <span class="o">=</span> <span class="n">events</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="na">getTimestamp</span><span class="p">();</span>
<span class="kt">long</span> <span class="n">endTime</span> <span class="o">=</span> <span class="n">events</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="mi">2</span><span class="p">).</span><span class="na">getTimestamp</span><span class="p">()</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">events</span><span class="p">.</span><span class="na">clear</span><span class="p">();</span>
<span class="n">streamClient</span><span class="p">.</span><span class="na">getEvents</span><span class="p">(</span><span class="n">streamId</span><span class="p">,</span> <span class="n">startTime</span><span class="p">,</span> <span class="n">endTime</span><span class="p">,</span> <span class="n">Integer</span><span class="p">.</span><span class="na">MAX_VALUE</span><span class="p">,</span> <span class="n">events</span><span class="p">);</span>

<span class="c1">// Write asynchronously to a stream</span>
<span class="n">streamId</span> <span class="o">=</span> <span class="n">NamespaceId</span><span class="p">.</span><span class="na">DEFAULT</span><span class="p">.</span><span class="na">stream</span><span class="p">(</span><span class="s">&quot;testAsync&quot;</span><span class="p">);</span>
<span class="n">events</span> <span class="o">=</span> <span class="n">Lists</span><span class="p">.</span><span class="na">newArrayList</span><span class="p">();</span>

<span class="n">streamClient</span><span class="p">.</span><span class="na">create</span><span class="p">(</span><span class="n">streamId</span><span class="p">);</span>

<span class="c1">// Send 10 async writes</span>
<span class="kt">int</span> <span class="n">msgCount</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">msgCount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
  <span class="n">streamClient</span><span class="p">.</span><span class="na">asyncSendEvent</span><span class="p">(</span><span class="n">streamId</span><span class="p">,</span> <span class="s">&quot;Testing &quot;</span> <span class="o">+</span> <span class="n">i</span><span class="p">);</span>
<span class="p">}</span>

<span class="c1">// Read them back; need to read it multiple times as the writes happen asynchronously</span>
<span class="k">while</span> <span class="p">(</span><span class="n">events</span><span class="p">.</span><span class="na">size</span><span class="p">()</span> <span class="o">!=</span> <span class="n">msgCount</span><span class="p">)</span> <span class="p">{</span>
  <span class="n">events</span><span class="p">.</span><span class="na">clear</span><span class="p">();</span>
  <span class="n">streamClient</span><span class="p">.</span><span class="na">getEvents</span><span class="p">(</span><span class="n">streamId</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">Long</span><span class="p">.</span><span class="na">MAX_VALUE</span><span class="p">,</span> <span class="n">msgCount</span><span class="p">,</span> <span class="n">events</span><span class="p">);</span>
<span class="p">}</span>

<span class="c1">// Check that there are no more events</span>
<span class="n">events</span><span class="p">.</span><span class="na">clear</span><span class="p">();</span>
<span class="k">while</span> <span class="p">(</span><span class="n">events</span><span class="p">.</span><span class="na">isEmpty</span><span class="p">())</span> <span class="p">{</span>
  <span class="n">events</span><span class="p">.</span><span class="na">clear</span><span class="p">();</span>
  <span class="n">streamClient</span><span class="p">.</span><span class="na">getEvents</span><span class="p">(</span><span class="n">streamId</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">Long</span><span class="p">.</span><span class="na">MAX_VALUE</span><span class="p">,</span> <span class="n">msgCount</span><span class="p">,</span> <span class="n">events</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>

</div>
    <div class="col-md-2">
      <div id="right-sidebar" class="bs-sidenav scrollable-y" role="complementary">
        <div id="localtoc-scrollspy">
        </div>
      </div>
    </div></div>
</div>
<!-- block main content end -->
<!-- block footer -->
<footer class="footer">
      <div class="container">
        <div class="row">
          <div class="col-md-2 footer-left"><a title="Workflow HTTP RESTful API" href="http-restful-api/workflow.html" />Previous</a></div>
          <div class="col-md-8 footer-center"><a class="footer-tab-link" href="table-of-contents/../../reference-manual/licenses/index.html">Copyright</a> &copy; 2014-2020 Cask Data, Inc.&bull; <a class="footer-tab-link" href="//docs.cask.co/cdap/6.1.1/cdap-docs-6.1.1-web.zip" rel="nofollow">Download</a> an archive or
<a class="footer-tab-link" href="//docs.cask.co/cdap">switch the version</a> of the documentation
          </div>
          <div class="col-md-2 footer-right"><a title="Javadocs" href="javadocs/index.html" />Next</a></div>
        </div>
      </div>
    </footer>
<!-- block footer end -->
<script type="text/javascript" src="_static/bootstrap-3.3.6/js/bootstrap.min.js"></script><script type="text/javascript" src="_static/js/bootstrap-sphinx.js"></script><script type="text/javascript" src="_static/js/abixTreeList-2.js"></script><script type="text/javascript" src="_static/js/cdap-dynamicscrollspy-4.js"></script><script type="text/javascript" src="_static/js/cdap-version-menu.js"></script><script type="text/javascript" src="_static/js/copy-to-clipboard.js"></script><script type="text/javascript" src="_static/js/jquery.mousewheel.min.js"></script><script type="text/javascript" src="_static/js/jquery.mCustomScrollbar.js"></script><script type="text/javascript" src="_static/js/js.cookie.js"></script><script type="text/javascript" src="_static/js/tabbed-parsed-literal-0.2.js"></script><script type="text/javascript" src="_static/js/cdap-onload-javascript.js"></script><script type="text/javascript" src="_static/js/cdap-version-menu.js"></script>
    <script src="https://cdap.gitee.io/docs/cdap/json-versions.js"/></script>
  </body>
</html>